/**
 * Created by wangfei on 2017/6/15.
 */

/**
 *
 *
 * */
var Ajax = {
    post: function(url, data, callback, errCallback) {
        $.ajax({
            type: 'POST',
            url: config.host + url,
            dataType: 'json',
			data: data,
            //data: JSON.stringify(data),
            //contentType: "application/json; charset=utf-8",
            success: callback,
            error: function(err){
                if(errCallback) errCallback(err);
            }
        })
    },
    get: function(url, data, callback, errCallback) {
        $.ajax({
            type: 'get',
            url: config.host + url,
            dataType:'json',
            data:data,
            contentType: "application/json; charset=utf-8",
			processData: false,
			contentType: false,
            success: callback,
            error: function(err){
                if(errCallback) errCallback(err);
            }
        })
    },
    sendImg: function(url, data, callback, errCallback){
        $.ajax({
            type: 'post',
            url: config.host + url,
            dataType: 'json',
            data: data,
            processData: false,
            contentType: false,
            success: callback,
            error: function(err){
                if(errCallback) errCallback(err);
            }
        })
    }
}
window.Ajax = Ajax;

(function(win, $){

    win.Api = {
        //登录
        login: function(data, callback){
            Ajax.post('login', data, callback);
        },
        //获取验证码
        verifyCode: function(){
            return config.host+ '/verifyCode?' + parseInt(Math.random()*1e7);
        },
		//退出
		logout: function(callback) {
			Ajax.post('logout', null, callback);
		},
		//首页
		home: function(callback) {
			Ajax.post('home.data', null, callback);
		}
    }

})(
 window,
 jQuery
)